#include "BaseUnit.h"
#include "CommonFunction.h"

//---------------------------------------------------------------
// BaseUnit
//---------------------------------------------------------------
int BaseUnit::LoadFromString(const char *string_data)
{
	const char *string_cur = string_data;
	char buf[BUFFER_LEN];
	int len_sum = 0;
	int len = 0;
	int ret = 0;

	ret = GetOneString(string_cur, buf, &len);
	assert(ret >= 0);
	this->id = atoi(buf);
	len_sum = len + 1;

	ret = GetOneString(string_cur + len_sum, buf, &len);
	assert(ret >= 0);
	this->type = atoi(buf);
	len_sum += len + 1;

	ret = GetOneString(string_cur + len_sum, buf, &len);
	assert(ret >= 0);
	this->trust = atoi(buf);
	len_sum += len + 1;

	ret = GetOneString(string_cur + len_sum, buf, &len);
	assert(ret >= 0);
	this->category_unit_id = atoi(buf);
	len_sum += len + 1;

	return len_sum;
}

String BaseUnit::GetDebugDetail(void) const
{
	char buf[BUFFER_LEN];
	sprintf_s(buf, sizeof(buf), "id=%-10d, type=%d, trust=%-5d, category=%d, ",
		this->GetId(), this->GetType(), this->GetTrust(), this->GetCategory());

	return buf;
}